
package frsf.cidisi.exercise.tp.situationCalculus;


import frsf.cidisi.faia.agent.Action;
import frsf.cidisi.faia.agent.NoAction;
import frsf.cidisi.faia.agent.Perception;
import frsf.cidisi.faia.agent.situationcalculus.SituationCalculusBasedAgent;
import frsf.cidisi.faia.exceptions.PrologConnectorException;
import frsf.cidisi.faia.solver.situationcalculus.SituationCalculus;

public class Indiana_Jones extends SituationCalculusBasedAgent {

    private Action lastAction = NoAction.getInstance();

    
    //No tocar
    public Indiana_Jones() throws PrologConnectorException {
        this.setAgentState(new Indiana_State());
    }

    //No tocar
    @Override
    public void tell(Action action) {
        Indiana_State kb = this.getAgentState();
        kb.tell(action);
    }

    //No tocar
    @Override
    public void see(Perception p) {
        this.getAgentState().updateState(p);
    }

    
    //No tocar
    @Override
    public Action selectAction() {
        this.setSolver(new SituationCalculus());

        Action selectedAction = null;
        try {
            selectedAction = this.getSolver().solve(new Object[]{this.getAgentState()});
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        this.lastAction = selectedAction;
        if(selectedAction!=null){
	        String[] cadenas= selectedAction.toString().split("_");
	        if(cadenas[0].equals("ViajarA")){
	        	Indiana_JonesMain.inter.viajar(cadenas[1]);
	        }
	        
	        if (cadenas[0].equals("tomar")) {
	        	Indiana_JonesMain.inter.tomarTesoro();
	        }
        }

        return selectedAction;
    }

    
    
    
    
    
    //ESTE NO APARECE EN PACMAN LOGIC AGENT
    @Override
    public Indiana_State getAgentState() {
        Indiana_State agentState = (Indiana_State) super.getAgentState();

        return agentState;
    }


    //ESTE NO APARECE EN PACMAN LOGIC AGENT
    public Action getLastAction() {
        return this.lastAction;
    }
}
